package com.example.demo.config;

import com.example.demo.component.MyLocalResolver;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Gzj
 * @Date 2022/7/8 10:54
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    //在controller中，进行跳转的时候使用return “index”，页面少的时候还挺清晰，但是一多就不好管理
    //所有WebMvcConfigurer有addViewControllers进行管理
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/itcom").setViewName("index");
    }

    //自定义的国际化组件就生效了
    @Bean
    public LocaleResolver localeResolver(){
        return  new MyLocalResolver();
    }
}


